-
Notifications
You must be signed in to change notification settings - Fork 149
feat: add auto-format files on save #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add auto-format files on save #467
Conversation
Add tests to verify CLI commands (tool, status) exit cleanly without hanging. The tests reproduce a bug where CLI commands hang indefinitely after displaying output. The root cause is that ensure_initialization() creates database connections via asyncio.run() that are not cleaned up before the event loop closes. These tests will fail until the fix is applied. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: Cedric Hurst <[email protected]>
Add optional automatic file formatting using external formatters (like Prettier)
when Basic Memory writes files. Includes a standalone `basic-memory format`
command for batch formatting existing files.
Configuration options:
- format_on_save: Enable/disable auto-formatting (default: false)
- formatter_command: Global formatter command (e.g., "prettier --write {file}")
- formatters: Per-extension formatters (e.g., {"md": "prettier --write {file}"})
- formatter_timeout: Max seconds to wait for formatter (default: 5.0)
Integration points:
- FileService.write_file() and update_frontmatter()
- MarkdownProcessor.write_file()
- All import commands
Closes basicmachines-co#466
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Signed-off-by: Cedric Hurst <[email protected]>
Users can now just set format_on_save=true and formatting will work out of the box (assuming Node.js is installed). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: Cedric Hurst <[email protected]>
|
Updated to default Now users can simply set |
Add optional automatic file formatting using mdformat (pure Python, no Node.js required): - Add `format_on_save` config option to enable automatic formatting - Use built-in mdformat for markdown files by default (no external dependencies) - Support GFM tables and YAML frontmatter via mdformat plugins - Allow external formatters via `formatter_command` config (e.g., Prettier) - Add per-extension formatter config via `formatters` dict - Add `basic-memory format` CLI command for batch formatting - Use FileService.is_markdown() for cloud compatibility (S3FileService) Based on PR #467 by Cedric Hurst (@divideby0) - refactored to use Python-based mdformat instead of requiring Node.js/Prettier. Closes #466 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Cedric Hurst <[email protected]> Co-Authored-By: Claude <[email protected]> Signed-off-by: phernandez <[email protected]>
|
Thank you for this contribution, @divideby0! 🙏 We've incorporated your work into #474 with some modifications:
Your original implementation for the CLI command, config options, and integration points was excellent and is preserved. We've credited you as a co-author in the commit. Closing this PR in favor of #474. Thanks again for the great feature idea and implementation! |
Summary
basic-memory formatCLI command for batch formatting existing filesformat_on_save,formatter_command,formatters,formatter_timeoutTest plan
format_file()function (11 tests)Closes #466
🤖 Generated with Claude Code